home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / QuitDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-02-03  |  2.8 KB  |  73 lines

  1. import java.awt.Button;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dialog;
  6. import java.awt.Event;
  7. import java.awt.FlowLayout;
  8. import java.awt.Font;
  9. import java.awt.Frame;
  10. import java.awt.Rectangle;
  11.  
  12. public class QuitDialog extends Dialog {
  13.    Button yesButton;
  14.    Button noButton;
  15.  
  16.    void yesButton_Clicked(Event event) {
  17.       ((Component)this).getParent().handleEvent(new Event(this, 201, (Object)null));
  18.    }
  19.  
  20.    void noButton_Clicked(Event event) {
  21.       ((Component)this).hide();
  22.    }
  23.  
  24.    public QuitDialog(Frame parent, boolean modal) {
  25.       super(parent, modal);
  26.       ((Container)this).setLayout(new FlowLayout(1, 20, 35));
  27.       ((Dialog)this).addNotify();
  28.       ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 317, ((Container)this).insets().top + ((Container)this).insets().bottom + 97);
  29.       ((Component)this).setFont(new Font("Dialog", 1, 12));
  30.       ((Component)this).setForeground(new Color(0));
  31.       ((Component)this).setBackground(new Color(16777215));
  32.       this.yesButton = new Button(" Yes ");
  33.       this.yesButton.reshape(((Container)this).insets().left + 112, ((Container)this).insets().top + 35, 44, 21);
  34.       this.yesButton.setFont(new Font("Dialog", 1, 12));
  35.       ((Container)this).add(this.yesButton);
  36.       this.noButton = new Button(" No  ");
  37.       this.noButton.reshape(((Container)this).insets().left + 161, ((Container)this).insets().top + 35, 39, 21);
  38.       this.noButton.setFont(new Font("Dialog", 1, 12));
  39.       ((Container)this).add(this.noButton);
  40.       ((Dialog)this).setTitle("Really Quit?");
  41.       ((Dialog)this).setResizable(false);
  42.    }
  43.  
  44.    public QuitDialog(Frame parent, String title, boolean modal) {
  45.       this(parent, modal);
  46.       ((Dialog)this).setTitle(title);
  47.    }
  48.  
  49.    public synchronized void show() {
  50.       Rectangle bounds = ((Component)this).getParent().bounds();
  51.       Rectangle abounds = ((Component)this).bounds();
  52.       ((Component)this).move(bounds.x + (bounds.width - abounds.width) / 2, bounds.y + (bounds.height - abounds.height) / 2);
  53.       super.show();
  54.    }
  55.  
  56.    public boolean handleEvent(Event event) {
  57.       if (event.id == 201) {
  58.          ((Component)this).hide();
  59.          return true;
  60.       } else {
  61.          if (event.target == this.noButton && event.id == 1001) {
  62.             this.noButton_Clicked(event);
  63.          }
  64.  
  65.          if (event.target == this.yesButton && event.id == 1001) {
  66.             this.yesButton_Clicked(event);
  67.          }
  68.  
  69.          return super.handleEvent(event);
  70.       }
  71.    }
  72. }
  73.